Computer graphics is the art and science of generating pictures, images, or other graphical or pictorial information with a computer. Generation of the pictures or images is commonly called rendering. Generally, in three-dimensional (3D) computer graphics, geometry that represents surfaces (or volumes) of objects in a scene is translated into pixels (picture elements), stored in a frame buffer, and then displayed on a display device.
Several different coordinate spaces will be used to transform an object in a scene to an image shown on a display. For instance, an object may commence from a model space where transformations have yet to occur. From the model space, vertices and normals of the object may be positioned and oriented through the use of one or more model transforms, resulting in a transformation into world space or world coordinates. Further, a view transform is applied to the models having world coordinates to define the position and orientation with respect to a camera position. The resulting space, often referred to as eye space or camera space, may facilitate various operations, such as projection and clipping functionality, as well as further transformations.
These further transformations from eye space may include the use of programmable shader programs, such as a vertex shader, pixel shader, and/or geometry shader, to be executed in a pool of parallel, multi-threaded execution units forming a computational core of a graphics processing unit (GPU). A shader generally refers to a program used in 3-dimensional (3D) computer graphics that may be used to determine the final surface properties of an object or image. Each object or group of objects may have specific visual properties related to the appearance of surfaces (e.g., materials, reflectance, shape, textures, etc.) and/or operations related to the same (e.g., required transformations) which may collectively be referred to as a rendering context for this object or group of objects. When rendering an object or group of objects for a given rendering context, a shader utilizes a constant data pool (e.g., context-specific constants stored in a constant buffer).
For instance, a vertex shader is generally applied to each vertex and runs on a programmable vertex processor. The vertex shader may define a method to compute vector space transformations and perform other computations. In computing the vector space transformations, various constants may be used. For instance, vertices (x, y, z, w) may be transformed to new vertices (x′, y′, z′, w′) through the use of a matrix (e.g., 4×4 matrix) of constants (e.g., C00, C01, C02, C03, . . . C33). These constants are typically stored in a constant buffer corresponding to a respective execution unit, the constants related to the rendering context of one or more 3D objects.
One challenge to existing systems occurs in regard to the frequent updating of at least a portion of the constants in the constant buffer due to rendering of the sequence of objects with different visual properties defined in an appropriate rendering context. In general, an update of constants requires “flushing” the entire constant buffer having the “old” context related data and loading “new” constants corresponding to a new context.
Further, the execution unit corresponding to the constant buffer, which may be running a plurality of threads, may be stalled during the flushing of the constant buffer. That is, the execution unit may flush the threads (e.g., to allow completion of processing using the previous constants) before execution using the set of new constants can commence. Thus, such rendering context switching (e.g., from a first context to a second context) in the shader running on a multi-threaded computational core may cause significant performance penalties.